package praktikumid.w09.p2;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;

/**
 * Panel for drawing. We extend Canvas here,
 * which makes some stuff easier (especially
 * for your homework).
 * @author Ago
 *
 */
public class DrawPanel extends Canvas {
	
	/**
	 * Let's store coordinates for oval
	 * in order to draw it within paint() method.
	 */
	private int ovalX = -1;
	/**
	 * Coordinate for the oval.
	 */
	private int ovalY = -1;

	/**
	 * Constructor.
	 */
	public DrawPanel() {
		setBackground(Color.WHITE);
	}
	
	/**
	 * Draws oval. This method
	 * actually does not draw anything,
	 * it just stores information to
	 * variables. Actual drawing takes
	 * place in paint() method.
	 */
	public void drawOval() {
		ovalX = 100;
		ovalY = 100;
		repaint();
		/*Graphics g = getGraphics();
		g.drawOval(100, 100, 70, 140);
		g.dispose();*/
		System.out.println("drawing oval");
	}
	
	/**
	 * Draws rectangle. This method actually
	 * does drawing, which is not recommended
	 * in this way. Rather store information
	 * in variables and do the drawing in paint() method.
	 */
	public void drawRectangle() {
		Graphics g = getGraphics();
		g.drawRect(200, 200, 70, 140);
		g.dispose();
		System.out.println("drawing rect");
	}

	/**
	 * Draws line.
	 */
	public void drawLine() {
		Graphics g = getGraphics();
		g.drawLine(0, 0, 600, 600);
		g.dispose();
		System.out.println("drawing line");
	}
	
	@Override
	public void paint(Graphics g) {
		// here we call parent's paint method
		super.paint(g);
		g.setColor(Color.BLUE);
		g.drawLine(300, 0, 0, 200);
		if (ovalX != -1) {
			// if oval coordinates are set, 
			// let's draw oval.
			g.drawOval(ovalX, ovalY, 70, 140);
		}
	}
}
